// 音频播放器类
        class AudioPlayer {
            constructor() {
                this.audio = new Audio();
                this.currentTrackIndex = 0;
                this.isPlaying = false;
                this.isShuffle = false;
                this.repeatMode = 0; // 0: 不重复, 1: 单曲循环, 2: 列表循环
                
                // DOM 元素
                this.playBtn = document.getElementById('play-btn');
                this.prevBtn = document.getElementById('prev-btn');
                this.nextBtn = document.getElementById('next-btn');
                this.shuffleBtn = document.getElementById('shuffle-btn');
                this.repeatBtn = document.getElementById('repeat-btn');
                this.progressBar = document.getElementById('progress-bar');
                this.progressHandle = document.getElementById('progress-handle');
                this.progressContainer = document.getElementById('progress-container');
                this.volumeBar = document.getElementById('volume-bar');
                this.volumeHandle = document.getElementById('volume-handle');
                this.volumeContainer = document.getElementById('volume-container');
                this.muteIcon = document.getElementById('mute-icon');
                this.currentTimeElement = document.getElementById('current-time');
                this.totalTimeElement = document.getElementById('total-time');
                this.songTitleElement = document.getElementById('song-title');
                this.songArtistElement = document.getElementById('song-artist');
                this.albumCoverElement = document.getElementById('album-cover');
                this.playlistItems = document.querySelectorAll('.playlist-item');
                this.albumContainer = document.getElementById('album-container');
                this.lyricsContent = document.getElementById('lyrics-content');
            }
            
            init() {
                // 设置初始音量
                this.audio.volume = 0.7;
                this.updateVolumeUI();
                
                // 加载第一首歌曲
                this.loadTrack(this.currentTrackIndex);
                
                // 绑定事件监听器
                this.bindEvents();
            }
            
            bindEvents() {
                // 播放/暂停按钮
                this.playBtn.addEventListener('click', () => {
                    if (this.isPlaying) {
                        this.pause();
                    } else {
                        this.play();
                    }
                });
                
                // 上一首/下一首按钮
                this.prevBtn.addEventListener('click', () => this.prevTrack());
                this.nextBtn.addEventListener('click', () => this.nextTrack());
                
                // 随机播放按钮
                this.shuffleBtn.addEventListener('click', () => {
                    this.isShuffle = !this.isShuffle;
                    this.updateShuffleUI();
                });
                
                // 重复播放按钮
                this.repeatBtn.addEventListener('click', () => {
                    this.repeatMode = (this.repeatMode + 1) % 3;
                    this.updateRepeatUI();
                });
                
                // 进度条控制
                this.progressContainer.addEventListener('click', (e) => this.seek(e));
                this.audio.addEventListener('timeupdate', () => this.updateProgress());
                
                // 音量控制
                this.volumeContainer.addEventListener('click', (e) => this.setVolume(e));
                this.muteIcon.addEventListener('click', () => this.toggleMute());
                
                // 歌曲加载完成
                this.audio.addEventListener('loadedmetadata', () => this.updateTotalTime());
                
                // 歌曲播放结束
                this.audio.addEventListener('ended', () => this.handleTrackEnd());
                
                // 播放列表项点击
                document.addEventListener('click', (e) => {
                    const playlistItem = e.target.closest('.playlist-item');
                    if (playlistItem) {
                        const index = parseInt(playlistItem.dataset.index);
                        this.loadTrack(index);
                        this.play();
                    }
                });
            }
            
            loadTrack(index) {
                if (index < 0 || index >= playlist.length) return;
                
                this.currentTrackIndex = index;
                const track = playlist[index];
                
                // 更新音频源
                this.audio.src = `audio/${track.file}`;
                
                // 更新UI
                this.songTitleElement.textContent = track.title;
                this.songArtistElement.textContent = track.artist;
                this.albumCoverElement.src = `img/${track.cover}`;
                this.albumCoverElement.alt = `${track.title}封面图`;
                
                // 更新歌词
                this.updateLyrics(track.lyrics || '');
                
                // 更新播放列表高亮
                this.updatePlaylistHighlight();
                
                // 重置进度条
                this.progressBar.style.width = '0%';
                this.progressHandle.style.left = '0%';
                this.currentTimeElement.textContent = '0:00';
                
                // 加载音频
                this.audio.load();
            }
            
            play() {
                this.audio.play()
                    .then(() => {
                        this.isPlaying = true;
                        this.updatePlayButton();
                        this.albumContainer.classList.add('rotating');
                        this.albumContainer.classList.remove('paused');
                    })
                    .catch(error => {
                        console.error('播放失败:', error);
                        alert('播放失败，请确保音频文件路径正确');
                    });
            }
            
            pause() {
                this.audio.pause();
                this.isPlaying = false;
                this.updatePlayButton();
                this.albumContainer.classList.add('paused');
            }
            
            prevTrack() {
                if (this.isShuffle) {
                    this.currentTrackIndex = this.getRandomTrackIndex();
                } else {
                    this.currentTrackIndex = (this.currentTrackIndex - 1 + playlist.length) % playlist.length;
                }
                this.loadTrack(this.currentTrackIndex);
                this.play();
            }
            
            nextTrack() {
                if (this.isShuffle) {
                    this.currentTrackIndex = this.getRandomTrackIndex();
                } else {
                    this.currentTrackIndex = (this.currentTrackIndex + 1) % playlist.length;
                }
                this.loadTrack(this.currentTrackIndex);
                this.play();
            }
            
            seek(e) {
                const rect = this.progressContainer.getBoundingClientRect();
                const pos = (e.clientX - rect.left) / rect.width;
                this.audio.currentTime = pos * this.audio.duration;
            }
            
            setVolume(e) {
                const rect = this.volumeContainer.getBoundingClientRect();
                const pos = (e.clientX - rect.left) / rect.width;
                this.audio.volume = Math.max(0, Math.min(1, pos));
                this.updateVolumeUI();
            }
            
            toggleMute() {
                this.audio.muted = !this.audio.muted;
                this.updateVolumeUI();
            }
            
            handleTrackEnd() {
                if (this.repeatMode === 1) {
                    // 单曲循环
                    this.audio.currentTime = 0;
                    this.play();
                } else if (this.repeatMode === 2 || this.isShuffle) {
                    // 列表循环或随机播放
                    this.nextTrack();
                } else {
                    // 不重复，播放完停止
                    this.pause();
                    this.audio.currentTime = 0;
                }
            }
            
            updateProgress() {
                const percent = (this.audio.currentTime / this.audio.duration) * 100;
                this.progressBar.style.width = `${percent}%`;
                this.progressHandle.style.left = `${percent}%`;
                
                // 更新当前时间显示
                this.currentTimeElement.textContent = this.formatTime(this.audio.currentTime);
            }
            
            updateTotalTime() {
                this.totalTimeElement.textContent = this.formatTime(this.audio.duration);
            }
            
            updateVolumeUI() {
                if (this.audio.muted || this.audio.volume === 0) {
                    this.volumeBar.style.width = '0%';
                    this.volumeHandle.style.left = '0%';
                    this.muteIcon.classList.remove('fa-volume-up', 'fa-volume-down');
                    this.muteIcon.classList.add('fa-volume-off');
                } else {
                    const volumePercent = this.audio.volume * 100;
                    this.volumeBar.style.width = `${volumePercent}%`;
                    this.volumeHandle.style.left = `${volumePercent}%`;
                    
                    if (this.audio.volume > 0.5) {
                        this.muteIcon.classList.remove('fa-volume-down', 'fa-volume-off');
                        this.muteIcon.classList.add('fa-volume-up');
                    } else {
                        this.muteIcon.classList.remove('fa-volume-up', 'fa-volume-off');
                        this.muteIcon.classList.add('fa-volume-down');
                    }
                }
            }
            
            updatePlayButton() {
                if (this.isPlaying) {
                    this.playBtn.innerHTML = '<i class="fa fa-pause text-xl"></i>';
                } else {
                    this.playBtn.innerHTML = '<i class="fa fa-play text-xl"></i>';
                }
            }
            
            updateShuffleUI() {
                if (this.isShuffle) {
                    this.shuffleBtn.classList.remove('text-gray-400');
                    this.shuffleBtn.classList.add('text-purple-500');
                } else {
                    this.shuffleBtn.classList.remove('text-purple-500');
                    this.shuffleBtn.classList.add('text-gray-400');
                }
            }
            
            updateRepeatUI() {
                switch (this.repeatMode) {
                    case 0: // 不重复
                        this.repeatBtn.classList.remove('text-purple-500');
                        this.repeatBtn.classList.add('text-gray-400');
                        this.repeatBtn.innerHTML = '<i class="fa fa-repeat text-xl"></i>';
                        break;
                    case 1: // 单曲循环
                        this.repeatBtn.classList.remove('text-gray-400');
                        this.repeatBtn.classList.add('text-purple-500');
                        this.repeatBtn.innerHTML = '<i class="fa fa-repeat text-xl"><span class="absolute text-xs bottom-0 right-0">1</span></i>';
                        break;
                    case 2: // 列表循环
                        this.repeatBtn.classList.remove('text-gray-400');
                        this.repeatBtn.classList.add('text-purple-500');
                        this.repeatBtn.innerHTML = '<i class="fa fa-repeat text-xl"></i>';
                        break;
                }
            }
            
            updatePlaylistHighlight() {
                document.querySelectorAll('.playlist-item').forEach((item, index) => {
                    if (index === this.currentTrackIndex) {
                        item.classList.add('active');
                    } else {
                        item.classList.remove('active');
                    }
                });
            }
            
            updateLyrics(lyrics) {
                if (lyrics) {
                    this.lyricsContent.innerHTML = lyrics.replace(/\n/g, '<br>');
                } else {
                    this.lyricsContent.innerHTML = '<p class="text-gray-500">暂无歌词</p>';
                }
            }
            
            formatTime(seconds) {
                if (isNaN(seconds)) return '0:00';
                const minutes = Math.floor(seconds / 60);
                seconds = Math.floor(seconds % 60);
                return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
            }
            
            getRandomTrackIndex() {
                let randomIndex;
                do {
                    randomIndex = Math.floor(Math.random() * playlist.length);
                } while (randomIndex === this.currentTrackIndex && playlist.length > 1);
                return randomIndex;
            }
        }
    